use "$data_out/provider_propensity.dta"





gen promotion1 = 0
gen promotion2 = 0
gen demotion1 = 0
gen demotion2 = 0
forval i = 2/15 {
replace promotion1 = 1 if inrange(dor`i',encdate +1, encdate+365) & rank`i' > begin_rank & !mi(rank`i')
replace promotion2 = 1 if inrange(dor`i',encdate +1, encdate+730) & rank`i' > begin_rank & !mi(rank`i')
replace demotion1 = 1 if inrange(dor`i',encdate +1, encdate+365) & rank`i' < begin_rank
replace demotion2 = 1 if inrange(dor`i',encdate +1, encdate+730) & rank`i' < begin_rank 

}
encode begin_rank, gen(grade)
save "$data_out/Promotions", replace



